<?php echo elgg_view('golfscore/title');?>
<div class="score-detail content">
<?php
$options = array("golf_course_id" => get_input('cid'));
$score_id = get_input('scoreid');

$score = elgg_get_golf_score(array('golf_score_id' => $score_id));
$score_details = elgg_get_golf_score_detail(array('golf_score_id' => $score_id));

$golf_course_cards = elgg_get_golf_course_card(array('golf_course_id' => $score[0]->golf_course_id));

$distance_map = array();
$par_map = array();

$tee = $score[0]->tee;
?>
 <div class="scoredetail_b">
 <div class="scoredetail_l">
 	<p class="tee" style="background: <?php echo $tee;?>; margin-bottom: 10px;width:35px;height:35px;float:left;" ></p>
 	<p class="scoredetail_rating scoredetail_block"><span><?php echo $score[0]->course_rating?></span><label>Rating</label></p> 
 	<p class="scoredetail_slope scoredetail_block"><span><?php echo $score[0]->course_slope?></span><label>Slope</label></p> 
 	<p class="scoredetail_total scoredetail_block"><span><?php echo $score[0]->total_score?></span><label>Total</label></p>
 
 </div>
 
 	
 	 <p class="scoredetail_date" style="position: absolute;top:-6px;right:-14px;"><label>@ <?php echo $score[0]->input_date?></label></p> 

 </div>
<?php

$scores_map = array();
foreach ($score_details as $detail){
	$scores_map[''.$detail->hole] = $detail;
}

foreach ($golf_course_cards as $golf_course_card) {
	$_distance = '';
	if($tee == 'gold') {
		$_distance = $golf_course_card->gold_tee_distance;
	} else if($tee == 'blue') {
		$_distance = $golf_course_card->blue_tee_distance;
	} else if($tee == 'white') {
		$_distance = $golf_course_card->white_tee_distance;
	} else if($tee == 'red') {
		$_distance = $golf_course_card->red_tee_distance;
	}

	?>
	<div class="hole"
		<?php 
		if(elgg_is_logged_in()
				&& elgg_get_logged_in_user_guid() == $score[0]->user_entity_id){
			echo "style=\"cursor: pointer;\" onclick=\"onEditScore('$score_id','$golf_course_card->hole','$tee')\"";
		}
		?>>
		<p class="hole_number"><span>Hole</span><?php echo $golf_course_card->hole ?></p>
		<p class="hole_par"><span>Par</span><?php echo $golf_course_card->par ?></p>
		<p class="hole_distance"><span>Distance</span><?php echo $_distance ?></p>
		<p class="hole_score"><span>Score</span>
			
			<?php
				if($scores_map[$golf_course_card->hole])
				{
					echo $scores_map[$golf_course_card->hole]->score;
				} else {
					echo "<label class='btn-editscore'>+</label>";
				}
				 
			?>
			<!-- <span class="icon_map"></span> -->
			
		</p>
	</div>

<?php }
?>

</div>
<script type="text/javascript">
	<?php 
		if(count($score) > 0){
			$cname = $score[0]->course_name;
			$uname = $score[0]->user_full_name;
		}
	?>

	changeTitle({
				'cname' :'<?php echo $cname;?>',
				'uname' :'<?php echo $uname;?>',
				'pageid': VIEW_SCORE_DETAIL,
				});
</script>
